package com.yochi.pictureseditor.images.converters;

public class PolarCoord {

	private double r;
	private double theta;
	
	public PolarCoord(int x, int y, int centerX, int centerY) {
		int xTrans = x-centerX;
		int yTrans = y-centerY;
		
		this.r = Math.sqrt(Math.pow(xTrans, 2) + Math.pow(yTrans, 2));
		
		if(xTrans > 0 && yTrans >= 0) {
			this.theta = Math.atan(Integer.valueOf(y-centerY).doubleValue() / Integer.valueOf(x-centerX).doubleValue());
			
		} else if(xTrans > 0 && yTrans < 0) {
			this.theta = Math.atan(Integer.valueOf(y-centerY).doubleValue() / Integer.valueOf(x-centerX).doubleValue()) + 2*Math.PI;
		
		} else if(xTrans == 0 && yTrans > 0) {
			this.theta = Math.PI / 2.0f;
			
		} else if(xTrans == 0 && yTrans < 0) {
			this.theta = 3.0f * Math.PI / 2.0f;
			
		} else if(xTrans < 0) {
			this.theta = Math.atan(Integer.valueOf(y-centerY).doubleValue() / Integer.valueOf(x-centerX).doubleValue()) + Math.PI;
		}
		
	}

	public double getR() {
		return r;
	}

	public void setR(double r) {
		this.r = r;
	}

	public double getTheta() {
		return theta;
	}

	public void setTheta(double theta) {
		this.theta = theta;
	}

	@Override
	public String toString() {
		return "PolarCoord [r=" + r + ", theta=" + theta + "]";
	}
	
}
